<?php
	error_reporting(E_ALL|E_STRICT);
	date_default_timezone_set('Europe/Madrid');
	
	set_include_path
	('.' 
		. PATH_SEPARATOR . './library/'
		. PATH_SEPARATOR . './application/models/'
		. PATH_SEPARATOR . './application/plugins/'
		. PATH_SEPARATOR . get_include_path()
	);
	
	include "Zend/Loader.php";
	Zend_Loader::registerAutoload();
	
	$config = new Zend_Config_Ini('./config/config.ini', 'general');
	$registry = Zend_Registry::getInstance();
	$registry->set('config', $config);
	
	//SETUP DATABASE
	$db = Zend_Db::factory
	(
		$config->db->adapter,
		$config->db->config->toArray()
	);
	
	Zend_Db_Table::setDefaultAdapter($db);
	Zend_Registry::set('db',$db); //PARA ZEND_AUTH
	
	//SETUP MVC
	$layoutOptions = array
	(
	   'layout'        =>  'index',
	   'layoutPath'    =>  'public/layouts/'
	);
	Zend_Layout::startMvc($layoutOptions);
	
	//SETUP CONTROLLER
	$frontController = Zend_Controller_Front::getInstance();
	$frontController->setControllerDirectory('./application/controllers');
	$frontController->throwExceptions(true);
	
	//REGISTRARMOS LOS PLUGINS
	$frontController->registerPlugin(new AuthPlugin());
	$frontController->registerPlugin(new AclPlugin());
	
	//RUN
	try { $frontController->dispatch(); }
	catch(Exception $e) 
	{
		//echo nl2br($e->__toString()); 
	}